package car.aistar.service.impl;

import car.aistar.dao.ReserveDao;
import car.aistar.entity.Reserve;
import car.aistar.service.ReserveService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Reserve)表服务实现类
 *
 * @author makejava
 * @since 2020-09-30 20:23:03
 */
@Service("reserveService")
public class ReserveServiceImpl implements ReserveService {
    @Autowired
    private ReserveDao reserveDao;
    @Autowired
    private ReserveService reserveService;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Reserve queryById(Long id) {
        return this.reserveDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Reserve> queryAllByLimit(int offset, int limit) {
        return this.reserveDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param reserve 实例对象
     * @return 实例对象
     */
    @Override
    public Reserve insert(Reserve reserve) {
        this.reserveDao.insert(reserve);
        return reserve;
    }

    /**
     * 修改数据
     *
     * @param reserve 实例对象
     * @return 实例对象
     */
    @Override
    public Reserve update(Reserve reserve) {
        this.reserveDao.update(reserve);
        return this.queryById(reserve.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.reserveDao.deleteById(id) > 0;
    }

    @Override
    public List<Reserve> queryAll(Reserve reserve) {
        return this.reserveDao.queryAll(reserve);
    }

    @Override
    public PageInfo<Reserve> findByPage(Long id,Integer pageNow, Integer pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<Reserve> reserveList = reserveService.findAllBySellerId(id);
        PageInfo<Reserve> petPageInfo = new PageInfo<>(reserveList);
        return petPageInfo;
    }

    @Override
    public List<Reserve> findAllBySellerId (Long id){
        List<Reserve> reserveList = reserveDao.findBySellerId(id);
        return reserveList;
    }
}